#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int minZeroArray(vector<int>& nums, vector<vector<int>>& queries) {
    int n = nums.size();
    vector<int> a(n + 1);
    auto check = [&](int k)->bool {
        ranges::fill(a, 0);
        for (int i = 0; i < k; i++)
        {
            auto& q = queries[i];
            int l = q[0], r = q[1], v = q[2];
            a[l] += v;
            a[r + 1] -= v;
        }
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            sum += a[i];
            if (nums[i] > sum)
                return false;
        }
        return true;
    };

    int m = queries.size();
    int l = 0, r = m + 1;
    while (l < r)
    {
        int mid = l + r >> 1;
        if (check(mid))
            r = mid;
        else l = mid + 1;
    }
    return l <= m ? l : -1;
}